
<template>
  <el-container >
    <el-header class="no-flex" height="auto">
      <el-form size="default" inline :model="searchForm" label-width="70px">
        <el-form-item label="模块名称" >
          <el-input v-model="searchForm.title" placeholder="请输入参数键名" :clearable="true" style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label="操作人员" >
          <el-input v-model="searchForm.operName" placeholder="请输入参数键名" :clearable="true" style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label="业务类型" >
          <el-select v-model="searchForm.businessType" placeholder="请选择业务类型" :clearable="true">
            <el-option v-for="item in dicts.system_operator_type" :key="item.id" :label="item.k" :value="item.v"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="执行状态"  >
          <el-select v-model="searchForm.status" placeholder="请选择执行状态" :clearable="true" style="width: 200px">
            <el-option v-for="item in dicts.system_global_expstatus" :key="item.id" :label="item.k" :value="item.v"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="操作时间" class="inline">
          <el-date-picker style="width: 200px"
                          v-model="chooseTime"
                          type="datetimerange"
                          range-separator="-"
                          start-placeholder="开始时间"
                          end-placeholder="结束时间"
                          clearable
                          value-format="YYYY-MM-DD HH:mm:ss"
                          @change="handleChange"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search"  @click="upsearch">
            <span>搜索</span>
          </el-button>
          <el-button type="default" icon="el-icon-RefreshLeft" @click="reset">
            <span>重置</span>
          </el-button>
        </el-form-item>
        <el-form-item style="display: flex; margin-bottom: 0">
          <el-button type="danger" :disabled="selection.length == 0" icon="el-icon-delete" @click="del">
            <span>删除</span>
          </el-button>
          <el-button type="danger" icon="el-icon-delete" @click="clean">
            <span>清空</span>
          </el-button>
        </el-form-item>
      </el-form>
    </el-header>
    <el-main class="nopadding">
      <el-table ref="table" row-key="id" @selection-change="selectionChange" :cell-style="{'text-align':'center'}" :header-cell-style="{'text-align':'center'}" hide-do :data="tableData">
        <el-table-column type="selection" width="50"></el-table-column>
        <el-table-column label="模块名称" prop="title" width="100"></el-table-column>
        <el-table-column label="业务类型" prop="businessType" width="100"></el-table-column>
        <el-table-column label="操作类别" prop="operatorType" width="100"></el-table-column>
        <el-table-column label="请求地址" prop="operUrl" ></el-table-column>
        <el-table-column label="请求方式" prop="requestMethod" width="100"></el-table-column>
        <el-table-column label="操作人员" prop="operName" width="100"></el-table-column>
        <el-table-column label="主机地址" prop="operIp" width="150"></el-table-column>
        <el-table-column label="操作地点" prop="operLocation" width="100"></el-table-column>
        <el-table-column label="状态" prop="status" width="100" >
          <template #default="{row}">
            <template v-for="item in dicts.system_global_expstatus">
              <el-tag v-if="row.status == item.v">{{item.k}}</el-tag>
            </template>
          </template>
        </el-table-column>
        <el-table-column label="操作时间" prop="operTime" width="100" :formatter="rendererDateTime"></el-table-column>
        <el-table-column label="操作" fixed="right" align="right" width="170">
          <template #default="scope">
            <el-button-group>
              <el-button text type="primary"  icon="el-icon-View"  @click="table_show(scope.row.id)">详情</el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
    </el-main>
    <el-footer style="display: flex;justify-content: flex-end">
      <el-pagination
        v-model:current-page="searchForm.currentPage"
        v-model:page-size="searchForm.pageSize"
        :page-sizes="[10, 20, 50, 100]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-footer>
  </el-container>
  <save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></save-dialog>

</template>

<script>
import saveDialog from './components/save.vue'
export default {
  name: 'loginlog',
  dicts: ['system_global_expstatus','system_operator_type'],
  components: {
    saveDialog
  },
  data() {
    return {
      dialog: {
        save: false
      },
      chooseTime:null,
      total:0,
      searchForm:{
        current:1,
        size:10,
        title:'',
        businessType:'',
        operName:'',
        status:'',
        beginTime:'',
        endTime:'',
      },
      selection: [],
      search: {
        keyword: null
      },
      tableData:[],
      enabled:null,
      options:[
        {
          enabled: 1,
          label: '启用',
        },
        {
          enabled: 0,
          label: '停用',
        },

      ]
    }
  },
  created() {
    this.getData()
  },
  methods: {
    // 请求数据
    async getData(){
      let res = await this.$API.log.operatelog.list.get(this.searchForm)
      this.tableData = res.data.records;
      this.total = res.data.total;
    },
    // 时间选择
    handleChange(val){
      this.searchForm.beginTime= val[0]
      this.searchForm.endTime= val[1]
    },
    //切换分页
    handleCurrentChange(e){
      this.searchForm.current = e;
      this.getData()
    },
    // 改变单页显示数量
    handleSizeChange(e){
      this.searchForm.size = e
      this.pagi.pageSize =e
      this.getData()
    },
    // 转换时间
    rendererDateTime(row, column, cellValue, index){
      return this.$TOOL.dateFormat(cellValue)
    },
    //添加
    add(){
      this.dialog.save = true
      this.$nextTick(() => {
        this.$refs.saveDialog.open('add').setData()
      })
    },
    //详情
    table_show(id){
      this.dialog.save = true
      this.$nextTick(() => {
        this.$refs.saveDialog.open('show').setData(id)
      })
    },
    //删除
    async del(){
      let res = await this.$API.log.operatelog.del.post(this.selection)
      if(res.code == 200){
        this.$message.success('删除成功')
        this.tableData = []
        this.getData()
      } else{
        this.$message.error('删除失败')
      }
    },
    //清空
    async clean(){
      let res = await this.$API.log.operatelog.clean.get()
      if(res.code == 200){
        this.$message.success('清空成功')
        this.tableData = []
        this.getData()
      } else{
        this.$message.error('清空失败')
      }
    },

    //表格选择后回调事件
    selectionChange(selection){
      selection.forEach((item,index)=>{
        if(this.selection.indexOf(item.id) == -1){
          this.selection.push(item.id)
        }
      })
    },
    //搜索
    async upsearch(){
      this.getData()
    },
    //重置功能
    reset(){
      this.searchForm={
        current:1,
          size:10,
          title:'',
          businessType:'',
          operName:'',
          status:'',
          beginTime:'',
          endTime:'',
      },
      this.tableData=[];
      this.getData()
    },
    //本地更新数据
    handleSaveSuccess(data, mode){
      if(mode =='add'){
        this.tableData = []
        this.getData()
      }else if(mode =='edit'){
        this.tableData=[]
        this.getData()
      }
    }
  }
}
</script>

<style scoped>

</style>
